package com.example.tianyidemo.controller;

import com.example.tianyidemo.pojo.Circle;
import com.example.tianyidemo.pojo.Result;
import com.example.tianyidemo.pojo.SearchRequest;
import com.example.tianyidemo.service.SreachCriceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@CrossOrigin//准许跨域请求
@RestController//包含@Controller（三层架构声明控制器）和@ResponseBody（转化json格式）
public class SearchcriceController {
    @Autowired
    private SreachCriceService sreachCriceService;
@PostMapping("/searchcrice")
   public Result searchcrice(@RequestBody SearchRequest request){
String searchStr = request.getSearchStr();
System.out.println(searchStr);
List<Circle> searchRusult = sreachCriceService.searchcrice(searchStr);
    if (!searchRusult.isEmpty()) {
        return Result.success(searchRusult);
    } else {
        return Result.error("未找到匹配房源");
    }
   }
}
